/*******************************************************************************
Copyright (C), 200{x}, Borqs Tech. Co., Ltd.
File Name: 
    lapi_ipc.h
Description: 
    IPC between LAPI client/server
History:  
    Date          Author                         Comments
    -----------   ---------------------------    --------------------
    Mar-19-2008   anle.zhou@borqs.com            Created
    Jun-18-2008   ray.fan@borqs.com              Ticket #731:AGPS/LBS: Settings - LAPI Client/Server Rework
    Feb-02-2009   anle.zhou@borqs.com            Android migration
*******************************************************************************/

#ifndef LAPI_IPC_H
#define LAPI_IPC_H

#include "lapi_comm.h"

#define LAPI_SRV_SYNC_PATH "/tmp/lapisock_sync"
#define LAPI_SRV_ASYNC_PATH "/tmp/lapisock_async"
#define LAPI_SRV_LISTENER_PATH "/tmp/lapisock_listener"

#define LAPI_MAX_CONN 64
#define LAPI_RSP_DATA_MAX 256
#define LAPI_REQ_DATA_MAX 256
#define LAPI_MSGSTRING_LONG 60 
#define LAPI_MSG_MAX (LAPI_RSP_DATA_MAX + LAPI_REQ_DATA_MAX + sizeof(LAPI_INT32) \
                      + sizeof(LAPI_MSG_TYPE_E) + sizeof(LAPI_RESULT_E))

typedef enum _LAPI_MSG_TYPE_E {
    LAPI_REQ_OPENSESSION = 0,
    LAPI_REQ_MO_STARTSESSION,
    LAPI_REQ_MT_STARTSESSION,
    LAPI_REQ_CLOSESESSION,
    LAPI_REQ_GETLOCATION,
    LAPI_REQ_ADD_LOCATIONLISTENER,
    LAPI_REQ_ADD_NMEALISTENER,
    LAPI_REQ_ADD_SUPLINITLISTENER,
    LAPI_REQ_ADD_GPRSCLOSELISTENER,
    LAPI_REQ_RM_LOCATIONLISTENER,
    LAPI_REQ_RM_NMEALISTENER,
    LAPI_REQ_RM_SUPLINITLISTENER,
    LAPI_REQ_RM_GPRSCLOSELISTENER,
    LAPI_REQ_MT_VERIFICATION_ACCEPT,
    LAPI_REQ_MT_VERIFICATION_REJECT,
    LAPI_REQ_MT_VERIFICATION_IGNORE,
    LAPI_REQ_UNSOLICITED_LISTENER,

    LAPI_RSP_OPENSESSION = 64,
    LAPI_RSP_MO_STARTSESSION,
    LAPI_RSP_MT_STARTSESSION,
    LAPI_RSP_CLOSESESSION,
    LAPI_RSP_GETLOCATION,
    LAPI_RSP_ADD_LOCATIONLISTENER,
    LAPI_RSP_ADD_NMEALISTENER,
    LAPI_RSP_ADD_SUPLINITLISTENER,
    LAPI_RSP_ADD_GPRSCLOSELISTENER,
    LAPI_RSP_RM_LOCATIONLISTENER,
    LAPI_RSP_RM_NMEALISTENER,
    LAPI_RSP_RM_SUPLINITLISTENER,
    LAPI_RSP_RM_GPRSCLOSELISTENER,
    LAPI_RSP_MT_VERIFICATION_ACCEPT,
    LAPI_RSP_MT_VERIFICATION_REJECT,
    LAPI_RSP_MT_VERIFICATION_IGNORE,

    //LAPI_UNSOLICITED_ICON_ENABLE = 100,
    LAPI_UNSOLICITED_ICON_VISIBLE_UPDATE = 100,
    LAPI_UNSOLICITED_ICON_FIXING,
    LAPI_UNSOLICITED_ICON_FIXED,
    LAPI_UNSOLICITED_ICON_UNFIXED,
    //LAPI_UNSOLICITED_ICON_DISABLE,
    LAPI_UNSOLICITED_CRITICAL_ERROR,
    LAPI_UNSOLICITED_SERVER_START,
    LAPI_UNSOLICITED_SERVER_CLOSE,
} LAPI_MSG_TYPE_E;

typedef struct _LAPI_MSG_H {
    LAPI_MSG_TYPE_E id;
    LAPI_INT8 string[LAPI_MSGSTRING_LONG];
} __attribute__((packed)) LAPI_MSG_H;

static LAPI_MSG_H LAPI_MSG_ARRAY[] = {
    {LAPI_REQ_OPENSESSION, "LAPI_REQ_OPENSESSION"},
    {LAPI_REQ_MO_STARTSESSION, "LAPI_REQ_MO_STARTSESSION"},
    {LAPI_REQ_MT_STARTSESSION, "LAPI_REQ_MT_STARTSESSION"},
    {LAPI_REQ_CLOSESESSION, "LAPI_REQ_CLOSESESSION"},
    {LAPI_REQ_GETLOCATION, "LAPI_REQ_GETLOCATION"},
    {LAPI_REQ_ADD_LOCATIONLISTENER, "LAPI_REQ_ADD_LOCATIONLISTENER"},
    {LAPI_REQ_ADD_NMEALISTENER, "LAPI_REQ_ADD_NMEALISTENER"},
    {LAPI_REQ_ADD_SUPLINITLISTENER, "LAPI_REQ_ADD_SUPLINITLISTENER"},
    {LAPI_REQ_ADD_GPRSCLOSELISTENER, "LAPI_REQ_ADD_GPRSCLOSELISTENER"},
    {LAPI_REQ_RM_LOCATIONLISTENER, "LAPI_REQ_RM_LOCATIONLISTENER"},
    {LAPI_REQ_RM_NMEALISTENER, "LAPI_REQ_RM_NMEALISTENER"},
    {LAPI_REQ_RM_SUPLINITLISTENER, "LAPI_REQ_RM_SUPLINITLISTENER"},
    {LAPI_REQ_RM_GPRSCLOSELISTENER, "LAPI_REQ_RM_GPRSCLOSELISTENER"},
    {LAPI_REQ_MT_VERIFICATION_ACCEPT, "LAPI_REQ_MT_VERIFICATION_ACCEPT"},
    {LAPI_REQ_MT_VERIFICATION_REJECT, "LAPI_REQ_MT_VERIFICATION_REJECT"},
    {LAPI_REQ_MT_VERIFICATION_IGNORE, "LAPI_REQ_MT_VERIFICATION_IGNORE"},
    {LAPI_REQ_UNSOLICITED_LISTENER, "LAPI_REQ_UNSOLICITED_LISTENER"},
    {LAPI_RSP_OPENSESSION, "LAPI_RSP_OPENSESSION"},
    {LAPI_RSP_MO_STARTSESSION, "LAPI_RSP_MO_STARTSESSION"},
    {LAPI_RSP_MT_STARTSESSION, "LAPI_RSP_MT_STARTSESSION"},
    {LAPI_RSP_CLOSESESSION, "LAPI_RSP_CLOSESESSION"},
    {LAPI_RSP_GETLOCATION, "LAPI_RSP_GETLOCATION"},
    {LAPI_RSP_ADD_LOCATIONLISTENER, "LAPI_RSP_ADD_LOCATIONLISTENER"},
    {LAPI_RSP_ADD_NMEALISTENER, "LAPI_RSP_ADD_NMEALISTENER"},
    {LAPI_RSP_ADD_SUPLINITLISTENER, "LAPI_RSP_ADD_SUPLINITLISTENER"},
    {LAPI_RSP_ADD_GPRSCLOSELISTENER, "LAPI_RSP_ADD_GPRSCLOSELISTENER"},
    {LAPI_RSP_RM_LOCATIONLISTENER, "LAPI_RSP_RM_LOCATIONLISTENER"},
    {LAPI_RSP_RM_NMEALISTENER, "LAPI_RSP_RM_NMEALISTENER"},
    {LAPI_RSP_RM_SUPLINITLISTENER, "LAPI_RSP_RM_SUPLINITLISTENER"},
    {LAPI_RSP_RM_GPRSCLOSELISTENER, "LAPI_RSP_RM_GPRSCLOSELISTENER"},
    {LAPI_RSP_MT_VERIFICATION_ACCEPT, "LAPI_RSP_MT_VERIFICATION_ACCEPT"},
    {LAPI_RSP_MT_VERIFICATION_REJECT, "LAPI_RSP_MT_VERIFICATION_REJECT"},
    {LAPI_RSP_MT_VERIFICATION_IGNORE, "LAPI_RSP_MT_VERIFICATION_IGNORE"},
    {LAPI_UNSOLICITED_ICON_VISIBLE_UPDATE, "LAPI_UNSOLICITED_ICON_VISIBLE_UPDATE"},
    //{LAPI_UNSOLICITED_ICON_ENABLE, "LAPI_UNSOLICITED_ICON_ENABLE"},
    {LAPI_UNSOLICITED_ICON_FIXING, "LAPI_UNSOLICITED_ICON_FIXING"},
    {LAPI_UNSOLICITED_ICON_FIXED, "LAPI_UNSOLICITED_ICON_FIXED"},
    {LAPI_UNSOLICITED_ICON_UNFIXED, "LAPI_UNSOLICITED_ICON_UNFIXED"},
    //{LAPI_UNSOLICITED_ICON_DISABLE, "LAPI_UNSOLICITED_ICON_DISABLE"},
    {LAPI_UNSOLICITED_CRITICAL_ERROR, "LAPI_UNSOLICITED_CRITICAL_ERROR"},
    {LAPI_UNSOLICITED_SERVER_START, "LAPI_UNSOLICITED_SERVER_START"},
    {LAPI_UNSOLICITED_SERVER_CLOSE, "LAPI_UNSOLICITED_SERVER_CLOSE"},
};

typedef struct _LAPI_MSG_REQ_S {
    LAPI_INT32 sessionID;
    LAPI_UINT8 msgType;
    LAPI_UINT8 data[LAPI_REQ_DATA_MAX];
} __attribute__((packed)) LAPI_MSG_REQ_S;

typedef struct _LAPI_MSG_RSP_S {
    LAPI_INT32 sessionID;
    LAPI_UINT8 msgType;
    LAPI_UINT8 result;
    LAPI_UINT8 data[LAPI_RSP_DATA_MAX];
} __attribute__((packed)) LAPI_MSG_RSP_S;

LAPI_INT32 LAPI_SendMsg(const LAPI_INT32 fd, const LAPI_UINT8* buff, const LAPI_UINT32 len);

LAPI_INT32 LAPI_RecvMsg(const LAPI_INT32 fd, LAPI_UINT8* buff);

void LAPI_PrintReq(const LAPI_MSG_REQ_S* msg);
void LAPI_PrintRsp(const LAPI_MSG_RSP_S* msg);

#endif /* LAPI_IPC_H */
